package com.example.blood_sugar.fragments;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.example.blood_sugar.R;
import com.example.blood_sugar.adapters.BloodSugarFragmentAdapter;
import com.example.blood_sugar.bean.BSRecord;
import com.example.blood_sugar.utils.ToastUtil;
import com.example.blood_sugar.view.DrawableTextView;
import com.hmy.popwindow.PopItemAction;
import com.hmy.popwindow.PopWindow;

import java.util.ArrayList;
import java.util.List;

/**
 * 血糖的起始界面，只有TabLayout和ViewPager
 */
public class BloodSugarFragment extends BaseFragment {

    private TabLayout tab;
    private ViewPager pager;
    private List<String> list;


    public static BloodSugarFragment newInstance(String text){
        Bundle bundle = new Bundle();
        bundle.putString("text",text);
        BloodSugarFragment bloodSugarFragment = new BloodSugarFragment();
        bloodSugarFragment.setArguments(bundle);
        return  bloodSugarFragment;
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        final View view = inflater.inflate(R.layout.fragment_blood_sugar, container, false);

        /*初始化界面*/
        initViews(view);
        /*初始化数据*/
        initData();
        /*设置Adapter*/
        pager.setAdapter(new BloodSugarFragmentAdapter(getActivity().getSupportFragmentManager(), list));
        /*Tab与ViewPager绑定*/
        tab.setupWithViewPager(pager);

        pager.setOffscreenPageLimit(3); // 设置缓存3个界面

        return view;
    }

    /*初始化数据*/
    private void initData() {
        list = new ArrayList<>();
        // String.format(Locale.CHINA,"第%02d页",i)
        list.add("7天");
        list.add("15天");
        list.add("30天");
    }

    /*初始化界面*/
    private void initViews(View view) {
        this.pager = view.findViewById(R.id.blood_sugar_pager);
        this.tab = view.findViewById(R.id.blood_sugar_tab);
    }

}
